﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using WebShop.Classes.DataSource;
using WebShop.DataService;

namespace WebShop.Classes.Auth
{
    /// <summary>
    /// Work with user profile
    /// </summary>
    public class FormsAuthenticationService : IFormsAuthentication
    {
        /// <summary>
        /// Set, authentificated user fact
        /// </summary>
        /// <param name="userName">Username</param>
        /// <param name="createPersistentCookie">SetCoookie</param>
        public void SignIn(string userName, bool createPersistentCookie)
        {
            FormsAuthentication.SetAuthCookie(userName, false);
        }

        /// <summary>
        /// Set, that user is logout
        /// </summary>
        public void SignOut()
        {
            FormsAuthentication.SignOut();
        }

        /// <summary>
        /// Return authentification 
        /// </summary>
        /// <returns>SignIn user info or NULL if not logined</returns>
        public User GetInfo()
        {
            return ConfigStorage.User;
        }

        /// <summary>
        /// Update logged user data
        /// </summary>
        /// <param name="user">User data</param>
        /// <returns>Updated user data or NULL if error</returns>
        public User SetUser(DataService.User user)
        {
            IDataSource dataSource = DataSourceFactory.Contruct();
            return dataSource.SetUser(user);
        }
    }
}